/**
 * \class CBulkSpaceProxy
 * \brief This is a space proxy to provide write/read/take in bulk mode to improve CSpaceProxy's performance.
 * \version 0.3.2
 *
 * \author Woo-Hyun Kim (woorung@nhncorp.com, woorung@gmail.com)
 * \author http://blog.naver.com/wisereign .
 *
 * \date 2007/10/9
 */
#ifndef CBulkSpaceProxyH
#define CBulkSpaceProxyH
//-----------------------------------------------------------------
#include <iostream>
#include <vector>
#include <map>
#include <iterator>

#include "CSpaceProxy.h"

using namespace std;

//-----------------------------------------------------------------
class CBulkSpaceProxy : public CSpaceProxy
{
private:
	int bulk_limit;

	map< CServiceInfo, vector< pair<string,string> > * > out_spaces;

	vector< pair<string,string> * > in_spaces;

protected:
	int bulk_write(const CServiceInfo &found_space, vector< pair<string,string> > *bulk_kv);

	int bulk_take(string &space_key, pair<string,string> &kv, char *cmd);

	int take(string &space_key, pair<string,string> &kv, char *cmd);

public:
	CBulkSpaceProxy();
	CBulkSpaceProxy(CWorkSpaces *wspace);
	virtual ~CBulkSpaceProxy();

	virtual int bulk(int limit);

	virtual int write(pair<string,string> &kv);
	virtual int write(string &space_key, pair<string,string> &kv);
	virtual int flush();

	virtual int take(pair<string,string> &kv);
	virtual int take(string &space_key, pair<string,string> &kv);
	virtual int takeIfExists(pair<string,string> &kv);
	virtual int takeIfExists(string &space_key, pair<string,string> &kv);
};
//-----------------------------------------------------------------
#endif
